package com.syni.mdd.yhd.common.all.controller.protect.groupChat;

/**
 * @className BmsBusinessController
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/15 14:25
 * @VERSION 1.0
 **/

import com.syni.mdd.sjb.common.component.utils.common.annotations.CheckParams;
import com.syni.mdd.sjb.common.component.utils.common.annotations.EntranceCheck;
import com.syni.mdd.yhd.common.all.constants.ResultMsg;
import com.syni.mdd.yhd.common.all.dto.requestDto.groupChart.GroupChatReDto;
import com.syni.mdd.yhd.common.all.service.BmsDxGroupChatService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ParamsMap;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.yhd.common.all.validationGroup.GroupFind;
import com.syni.mdd.yhd.common.all.validationGroup.GroupInsert;
import com.syni.mdd.yhd.common.all.validationGroup.GroupUpdate;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/groupChat")
@Log4j2
public class BmsDxGroupChatController {
    @Autowired
    BmsDxGroupChatService bmsDxGroupChatService;

    /**
     * @Description 创建群聊
     * @Param GroupChatReDto
     * @return Map
     * @Author: cfx
     * @Date: 2019/9/9
     */
    @PostMapping("/create")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> create(@RequestBody @Validated({GroupInsert.class}) GroupChatReDto groupChatReDto) throws Exception {
        Map<String,Object> resultMap;
        try {
            resultMap = bmsDxGroupChatService.create(groupChatReDto);
        }catch (Exception e){
            log.error(e.getMessage(),e);
            resultMap = ResultMapHelper.failure(ResultMsg.HAND_FAIL);
        }
        return resultMap;
    }

    @PostMapping("/checkIsUpdateGroupName")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> checkIsUpdateGroupName(@RequestBody @Validated GroupChatReDto groupChatReDto){
        return bmsDxGroupChatService.checkIsUpdateGroupName(groupChatReDto);
    }

    @PostMapping("/update")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> update(@RequestBody @Validated({GroupUpdate.class}) GroupChatReDto groupChatReDto){
        return bmsDxGroupChatService.update(groupChatReDto);
    }

    @PostMapping("/getBusinessGroupChat")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> getBusinessGroupChat(@RequestBody @Validated({GroupFind.class}) GroupChatReDto groupChatReDto){
        return bmsDxGroupChatService.getBusinessGroupChat(groupChatReDto);
    }


    /**
     * @Description 商户端获取群成员
     * @Author: cfx
     * @Date: 2019/12/3
     */
    @PostMapping("/getBusinessGroupMembers")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> getBusinessGroupMembers(@RequestBody @Validated({GroupFind.class}) GroupChatReDto groupChatReDto){
        return bmsDxGroupChatService.getBusinessGroupMembers(groupChatReDto);
    }


    /**
     * @Description 商户端踢人功能
     * @Param GroupChatReDto
     * @return Map
     * @Author: cfx
     * @Date: 2019/9/9
     */
    @PostMapping("/removeGroupMember")
    @CheckParams(checkAuth = true)
    public Map<String,Object> removeGroupMember(@RequestBody ParamsMap paramsMap){
        return bmsDxGroupChatService.removeGroupMember(paramsMap);
    }

    
    /**
     * @Description 商户端禁言功能
     * @Param GroupChatReDto
     * @return Map
     * @Author: cfx
     * @Date: 2019/9/9
     */
    @PostMapping("/banned")
    @CheckParams(checkAuth = true)
    public Map<String,Object> banned(@RequestBody ParamsMap paramsMap){
        return bmsDxGroupChatService.banned(paramsMap);
    }



    /**
     * @Description 群资料
     * @Param GroupChatReDto
     * @return Map
     * @Author: cfx
     * @Date: 2019/9/9
     */
    @PostMapping("/getGroupData")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> getGroupData(@RequestBody @Validated({GroupFind.class}) GroupChatReDto groupChatReDto) throws Exception {
        return bmsDxGroupChatService.getGroupData(groupChatReDto);
    }

    /**
     * @Description 获取群列表
     * @Author: cfx
     * @Date: 2019/10/10
     */
    @PostMapping("/userGetMyGroup")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> userGetMyGroup(@RequestBody @Validated({GroupFind.class}) GroupChatReDto groupChatReDto){
        return bmsDxGroupChatService.userGetMyGroup(groupChatReDto);
    }

    /**
     * @Description 用户端获取群资料
     * @Author: cfx
     * @Date: 2019/10/10
     */
    @PostMapping("/userGetGroupData")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> userGetGroupData(@RequestBody @Validated({GroupFind.class}) GroupChatReDto groupChatReDto){
        return bmsDxGroupChatService.userGetGroupData(groupChatReDto);
    }



    /**
     * @Description 用户端获取群成员
     * @Author: cfx
     * @Date: 2019/10/10
     */
    @PostMapping("/userGetGroupMembers")
    @EntranceCheck
    public Map<String,Object> userGetGroupMembers(@RequestBody @Validated({GroupFind.class}) GroupChatReDto groupChatReDto){
        return bmsDxGroupChatService.userGetGroupMembers(groupChatReDto);
    }



    /**
     * @Description 用户加群
     * @Author: cfx
     * @Date: 2019/10/10
     */
    @PostMapping("/userJoinGroup")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> userJoinGroup(@RequestBody @Validated({GroupFind.class}) GroupChatReDto groupChatReDto){
        return bmsDxGroupChatService.userJoinGroup(groupChatReDto);
    }

    /**
     * @Description 推荐群
     * @Author: cfx
     * @Date: 2019/10/10
     */
    @PostMapping("/userGetQualityGroup")
    @CheckParams(checkAuth = true)
    public Map<String,Object> userGetQualityGroup(@RequestBody ParamsMap paramsMap){
        return bmsDxGroupChatService.userGetQualityGroup(paramsMap);
    }

    /**
     * @Description 退群
     * @Author: cfx
     * @Date: 2019/10/10
     */
    @PostMapping("/userBackGroup")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> userBackGroup(@RequestBody @Validated({GroupFind.class}) GroupChatReDto groupChatReDto){
        return bmsDxGroupChatService.userBackGroup(groupChatReDto);
    }

    /**
     * @Description 进入群，是否显示群公告
     * @Author: cfx
     * @Date: 2019/10/10
     */
    @PostMapping("/groupAnnounPro")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> groupAnnounPro(@RequestBody @Validated({GroupFind.class}) GroupChatReDto groupChatReDto){
        return bmsDxGroupChatService.groupAnnounPro(groupChatReDto);
    }


    /**
     * @Description 修改我在本群的群名称
     * @Author: cfx
     * @Date: 2019/10/10
     */
    @PostMapping("/updateMyNameInGroup")
    @CheckParams(checkAuth = true,params = {"updateName"})
    public Map<String,Object> updateMyNameInGroup(@RequestBody ParamsMap paramsMap){
        return bmsDxGroupChatService.updateMyNameInGroup(paramsMap);
    }

    /**
     * @Description 开启商家促销提醒
     * @Author: cfx
     * @Date: 2019/10/10
     */
    @PostMapping("/startRemind")
    @EntranceCheck(checkAuth = true)
    public Map<String,Object> startRemind(@RequestBody GroupChatReDto groupChatReDto){
        return bmsDxGroupChatService.startRemind(groupChatReDto);
    }

    /**
     * @Description 是否开启置顶聊天
     * @Author: cfx
     * @Date: 2019/10/10
     */
    @PostMapping("/isTopChat")
    @CheckParams(checkAuth = true)
    public Map<String,Object> isTopChat(@RequestBody ParamsMap paramsMap){
        return bmsDxGroupChatService.isTopChat(paramsMap);
    }

    /**
     * @Description 券库分享到群聊
     * @Author: cfx
     * @Date: 2019/10/9
     */
    @PostMapping("/shareToGroupChat")
    @CheckParams(checkAuth = true)
    public Map<String,Object> shareToGroupChat(@RequestBody ParamsMap paramsMap){
        return bmsDxGroupChatService.shareToGroupChat(paramsMap);
    }


    /**
     * @Description 券库分享到群聊
     * @Author: cfx
     * @Date: 2019/10/9
     */
    @PostMapping("/testSendGroupChat")
    public Map<String,Object> testSendGroupChat(@RequestBody ParamsMap paramsMap){
        return bmsDxGroupChatService.testSendGroupChat(paramsMap);
    }

}
